import { Router } from 'express';
import { ClientFloorController } from '../../api/controllers/floorController';
import { authenticateClient } from '../../middleware/auth';

const router = Router();
const floorController = new ClientFloorController();

/**
 * @swagger
 * tags:
 *   name: 客户端楼层
 *   description: 客户端楼层相关接口
 */

/**
 * @swagger
 * /api/client/floors:
 *   get:
 *     summary: 获取楼层列表
 *     tags: [客户端楼层]
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 20
 *         description: 每页数量
 *       - in: query
 *         name: venueId
 *         schema:
 *           type: integer
 *         description: 场馆ID（可选，用于筛选）
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *           default: ACTIVE
 *           enum: [ACTIVE, INACTIVE]
 *         description: 楼层状态
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取楼层列表成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     items:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: integer
 *                           venueId:
 *                             type: integer
 *                           venue:
 *                             type: string
 *                           venueInfo:
 *                             type: object
 *                             properties:
 *                               id:
 *                                 type: integer
 *                               name:
 *                                 type: string
 *                               description:
 *                                 type: string
 *                               address:
 *                                 type: string
 *                               city:
 *                                 type: string
 *                               country:
 *                                 type: string
 *                               status:
 *                                 type: string
 *                           name:
 *                             type: string
 *                           level:
 *                             type: integer
 *                           description:
 *                             type: string
 *                           floorPlanUrl:
 *                             type: string
 *                           status:
 *                             type: string
 *                           performanceCount:
 *                             type: integer
 *                           artist:
 *                             type: object
 *                             nullable: true
 *                           upcomingPerformances:
 *                             type: array
 *                     pagination:
 *                       type: object
 *                       properties:
 *                         total:
 *                           type: integer
 *                         page:
 *                           type: integer
 *                         limit:
 *                           type: integer
 *                         totalPages:
 *                           type: integer
 *       400:
 *         description: 无效的场馆ID
 */
router.get('/', authenticateClient, floorController.getFloorList.bind(floorController));

/**
 * @swagger
 * /api/client/floors/search:
 *   get:
 *     summary: 搜索楼层
 *     tags: [客户端楼层]
 *     parameters:
 *       - in: query
 *         name: keyword
 *         required: true
 *         schema:
 *           type: string
 *         description: 搜索关键词（楼层名称、描述或场馆）
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 20
 *         description: 每页数量
 *       - in: query
 *         name: venueId
 *         schema:
 *           type: integer
 *         description: 场馆ID（可选，用于筛选）
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *           default: ACTIVE
 *           enum: [ACTIVE, INACTIVE]
 *         description: 楼层状态
 *     responses:
 *       200:
 *         description: 搜索成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 搜索楼层成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     items:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: integer
 *                           venueId:
 *                             type: integer
 *                           venue:
 *                             type: string
 *                           name:
 *                             type: string
 *                           level:
 *                             type: integer
 *                           description:
 *                             type: string
 *                           floorPlanUrl:
 *                             type: string
 *                           status:
 *                             type: string
 *                           performanceCount:
 *                             type: integer
 *                           hasActivePerformances:
 *                             type: boolean
 *                     pagination:
 *                       type: object
 *                       properties:
 *                         total:
 *                           type: integer
 *                         page:
 *                             type: integer
 *                         limit:
 *                           type: integer
 *                         totalPages:
 *                           type: integer
 *       400:
 *         description: 搜索关键词不能为空或无效的场馆ID
 */
router.get('/search', authenticateClient, floorController.searchFloors.bind(floorController));

/**
 * @swagger
 * /api/client/floors/{id}:
 *   get:
 *     summary: 获取楼层详情
 *     tags: [客户端楼层]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 楼层ID
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取楼层详情成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     id:
 *                       type: integer
 *                     venueId:
 *                       type: integer
 *                     venue:
 *                       type: string
 *                     venueInfo:
 *                       type: object
 *                       properties:
 *                         id:
 *                           type: integer
 *                         name:
 *                           type: string
 *                         description:
 *                           type: string
 *                         address:
 *                           type: string
 *                         city:
 *                           type: string
 *                         country:
 *                           type: string
 *                         status:
 *                           type: string
 *                         capacity:
 *                           type: integer
 *                     name:
 *                       type: string
 *                     level:
 *                       type: integer
 *                     description:
 *                       type: string
 *                     floorPlanUrl:
 *                       type: string
 *                     status:
 *                       type: string
 *                     createdAt:
 *                       type: string
 *                       format: date-time
 *                     updatedAt:
 *                       type: string
 *                       format: date-time
 *                     performanceCount:
 *                       type: integer
 *                     upcomingPerformances:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: integer
 *                           title:
 *                             type: string
 *                           startTime:
 *                             type: string
 *                             format: date-time
 *                           endTime:
 *                             type: string
 *                             format: date-time
 *                           status:
 *                             type: string
 *                           artist:
 *                             type: object
 *                             properties:
 *                               id:
 *                                 type: integer
 *                               name:
 *                                 type: string
 *                               avatar:
 *                                 type: string
 *                               description:
 *                                 type: string
 *                               genre:
 *                                 type: string
 *                     pastPerformances:
 *                       type: array
 *                       items:
 *                         type: object
 *                     ongoingPerformances:
 *                       type: array
 *                       items:
 *                         type: object
 *       400:
 *         description: 无效的楼层ID
 *       404:
 *         description: 楼层不存在或已禁用
 */
router.get('/:id', authenticateClient, floorController.getFloorDetail.bind(floorController));

/**
 * @swagger
 * /api/client/floors/venue/{venueId}:
 *   get:
 *     summary: 按场馆获取楼层列表
 *     tags: [客户端楼层]
 *     parameters:
 *       - in: path
 *         name: venueId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *           default: ACTIVE
 *           enum: [ACTIVE, INACTIVE]
 *         description: 楼层状态
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取场馆楼层列表成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     venue:
 *                       type: string
 *                     venueInfo:
 *                       type: object
 *                       properties:
 *                         id:
 *                           type: integer
 *                         name:
 *                           type: string
 *                         description:
 *                           type: string
 *                         address:
 *                           type: string
 *                         city:
 *                           type: string
 *                         country:
 *                           type: string
 *                     floors:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: integer
 *                           venueId:
 *                             type: integer
 *                           venue:
 *                             type: string
 *                           name:
 *                             type: string
 *                           level:
 *                             type: integer
 *                           description:
 *                             type: string
 *                           floorPlanUrl:
 *                             type: string
 *                           status:
 *                             type: string
 *                           performanceCount:
 *                             type: integer
 *                           hasActivePerformances:
 *                             type: boolean
 *                     totalFloors:
 *                       type: integer
 *       400:
 *         description: 场馆ID不能为空或无效的场馆ID
 *       404:
 *         description: 场馆不存在或已停用
 */
router.get('/venue/:venueId', authenticateClient, floorController.getFloorsByVenue.bind(floorController));

/**
 * @swagger
 * /api/client/floors/venue/{venueId}/stats:
 *   get:
 *     summary: 获取场馆楼层统计信息
 *     tags: [客户端楼层]
 *     parameters:
 *       - in: path
 *         name: venueId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取场馆楼层统计信息成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     venueId:
 *                       type: integer
 *                     venueName:
 *                       type: string
 *                     totalFloors:
 *                       type: integer
 *                       description: 总楼层数
 *                     activeFloors:
 *                       type: integer
 *                       description: 活跃楼层数
 *                     inactiveFloors:
 *                       type: integer
 *                       description: 非活跃楼层数
 *                     floorsWithPerformances:
 *                       type: integer
 *                       description: 有演出的楼层数量
 *                     levelDistribution:
 *                       type: array
 *                       description: 楼层层级分布
 *                       items:
 *                         type: object
 *                         properties:
 *                           level:
 *                             type: integer
 *                             description: 楼层层级
 *                           count:
 *                             type: integer
 *                             description: 该层级的楼层数量
 *       400:
 *         description: 场馆ID不能为空或无效的场馆ID
 *       404:
 *         description: 场馆不存在或已停用
 */
router.get('/venue/:venueId/stats', authenticateClient, floorController.getVenueFloorStats.bind(floorController));

export default router;
